

// actionCreators.js
import {
  ADD_NUMBER,
  SUB_NUMBER,
  ADD_BANNER,
  ADD_RECOMMEND,

  FETCH_MULTI_DATA,
  FETCH_MULTI_DATA_FAIL
} from './constants.js'

import {getMultidata} from 'api/list'

export function addAction(num){
  return {
    type: ADD_NUMBER,
    num
  }
}
export const addAction1 = (num) => {
  return {
    type: ADD_NUMBER,
    num
  }
} 
export const subAction = num => ({
  type: SUB_NUMBER,
  num
})

// 轮播和推荐数据
export const addBannersAction = banners => ({
  type: ADD_BANNER,
  banners
})

export const addRecommendAction = recommend => ({
  type: ADD_RECOMMEND,
  recommend
})


// redux-thunk 实现异步操作
// export const getMultidataAsyncAction = async (dispatch, getState) => {
//   const response = await getMultidata()
//   if (response.code === 200) {
//     const data = response.rows
//     dispatch(addBannersAction(data))
//     dispatch(addRecommendAction(data))
//   }
// }
// export async function getMultidataAsyncAction(dispatch, getState){
//   const response = await getMultidata()
//   if (response.code === 200) {
//     const data = response.rows
//     dispatch(addBannersAction(data))
//     dispatch(addRecommendAction(data))
//   }
// }


// 使用redux-saga实现异步操作  拦截的actionType
export const fetchMultidataAsyncAction = () => ({
  type: FETCH_MULTI_DATA,
})
export const fetchMultidataFailAsyncAction = (errMsg) => ({
  type: FETCH_MULTI_DATA_FAIL,
  errMsg
})